﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Deviders
{
    public class Permutation
    {
       

        public static void permuteString(String beginningString, String endingString)
        {

            if (endingString.Length <= 1)
                Console.WriteLine(beginningString + endingString);
            else
                for (int i = 0; i < endingString.Length; i++)
                {

                    String newString = endingString.Substring(0, i) + endingString.Substring(i + 1);

                    permuteString(beginningString + endingString.ElementAt(i), newString);

                }
        }
    }

    class Program
    {
        static int countOccuranceOfANumber(int number, int[] array)
        {
            int counter = 0;
            for (int index = 0; index < array.Length; index++)
            {
                if (number == array[index])
                {
                    counter++;
                }
            }
            return counter;
        }
        static int[] removeZeros(int[] membersOfASequence)
        {
            int ocuranceOfZero = countOccuranceOfANumber(0, membersOfASequence);
            int[] swapArray = new int[membersOfASequence.Length - ocuranceOfZero];
            int swapIndex = 0;
            for (int j = 0; j < membersOfASequence.Length ; j++)
            {
                if (membersOfASequence[j] != 0)
                {
                    swapArray[swapIndex] = membersOfASequence[j];
                    swapIndex++;
                }            
            }
            return swapArray;


        }

        static int numberOfPermutations(int number)
        {
            int permutations = 1;
            for (int index = 1; index <= number; index++)
            {
                permutations *= index;
            }
            return permutations;
        }
        static int deviderCounter(int number)
        {
            int counter = 0;
            for (int index = 1; index < number / 2; index++)
            {
                if (number % index == 0)
                {
                    counter++;
                }
            }
            counter++;
            return counter;
        }

        static void sort(int[] unsortedArray)
        {
           // int[] sortedArray = new int[unsortedArray.Length];
            int min = 0;
            for (int index = 0; index < unsortedArray.Length - 1 ; index++)
            {
                min = unsortedArray[index];
                for (int index2 = index + 1; index2 < unsortedArray.Length; index2++)
                {
                    if (unsortedArray[index] > unsortedArray[index2])
                    {
                        int swapValue = unsortedArray[index];
                        unsortedArray[index] = unsortedArray[index2];
                        unsortedArray[index2] = swapValue;
                    }
                }               
            }
        }
        static bool NextPermutation<T>(IList<T> a) where T : IComparable
        {
            if (a.Count < 2) return false;
            var k = a.Count - 2;

            while (k >= 0 && a[k].CompareTo(a[k + 1]) >= 0) k--;
            if (k < 0) return false;

            var l = a.Count - 1;
            while (l > k && a[l].CompareTo(a[k]) <= 0) l--;

            var tmp = a[k];
            a[k] = a[l];
            a[l] = tmp;

            var i = k + 1;
            var j = a.Count - 1;
            while (i < j)
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                i++;
                j--;
            }

            return true;
        }

        static int theNumberWithLeastDeviders(int[] membersOfASequence)
        {
            int numberWithLeastDeviders = gennerationNumberFromArray(membersOfASequence); 
            int lestDeviders = 1000000000;
            do
            {
                int number = gennerationNumberFromArray(membersOfASequence);
                int currentNumberOfDeviders = deviderCounter(number);
                if (lestDeviders > currentNumberOfDeviders )
                {
                    lestDeviders = currentNumberOfDeviders;
                    numberWithLeastDeviders = number;
                }
                else if (lestDeviders == currentNumberOfDeviders && number < numberWithLeastDeviders)                
                {
                    lestDeviders = currentNumberOfDeviders;
                    numberWithLeastDeviders = number;
                }
            }
            while (NextPermutation(membersOfASequence));
            return numberWithLeastDeviders;
            
        }
        static int gennerationNumberFromArray(int[] digitArray)
        {
            int returnedNumber = 0;
            for (int index = 0; index < digitArray.Length; index++)
            {
                returnedNumber *= 10;
                returnedNumber += digitArray[index];
            }

            return returnedNumber;


        }
        static void Main(string[] args)
        {
            int numberOfElements = int.Parse(Console.ReadLine());
            int[] membersOfASequence = new int[numberOfElements];
            for (int i = 0; i < numberOfElements ; i++)
            {
                membersOfASequence[i] = int.Parse(Console.ReadLine());
            }
            //int[] withoutZerosArray = removeZeros(membersOfASequence);
           // Console.WriteLine();

            //Console.WriteLine(gennerationNumberFromArray(membersOfASequence));
            sort(membersOfASequence);
            Console.WriteLine(theNumberWithLeastDeviders(membersOfASequence));
            //Console.WriteLine(deviderCounter(12));
            //Console.WriteLine(gennerationNumberFromArray(membersOfASequence));

        }
    }
}
